package com.wetao.lib_common.view.voicerecorder;

/**
 * desc:   sd卡路径操作类
 * author: wangshanhai
 * email: ilikeshatang@gmail.com
 * date: 2017/10/30 18:35
 */

import android.content.Context;
import android.os.Environment;

import com.wetao.lib_common.Constants;

import java.io.File;

public class PathUtil {
    public static String pathPrefix="";
    private static File storageDir = null;
    private static PathUtil instance = null;
    private File voicePath = null;

    private PathUtil() {
    }

    public static PathUtil getInstance() {
        if(instance == null) {
            instance = new PathUtil();
        }

        return instance;
    }

    public void createDirs(String var1, String var2, Context var3) {
        String var4 = var3.getPackageName();
        pathPrefix = "/Android/data/" + var4 + "/";
        this.voicePath = generateVoicePath(var1, var2, var3);
        if(!this.voicePath.exists()) {
            this.voicePath.mkdirs();
        }
    }

    public File getVoicePath() {
        return this.voicePath;
    }

    private File getStorageDir(Context var0) {
        if(storageDir == null) {
            //File var1 = Environment.getExternalStorageDirectory();
            File var1 = new File(Constants.FILE_PATH);
            if(var1.exists()) {
                return var1;
            }

            storageDir = var0.getFilesDir();
        }

        return storageDir;
    }

    private File generateVoicePath(String var0, String var1, Context var2) {
        String var3 = null;
        var3 = pathPrefix + var0 + "/" + var1 + "/";
        return new File(getStorageDir(var2), var3);
    }
}
